<?php

namespace yiike\core\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use \yiike\core\models\base\Notice as BaseNotice;

/**
 * This is the model class for table "core_notice".
 */
class Notice extends BaseNotice
{
    const LEVEL_INFO    = 1;
    const LEVEL_SUCCESS = 2;
    const LEVEL_ERROR   = 3;
    const LEVEL_WARNING = 4;

    public $levelOptions = [
        self::LEVEL_INFO    => '消息',
        self::LEVEL_SUCCESS => '成功',
        self::LEVEL_ERROR   => '错误',
        self::LEVEL_WARNING => '警告',
    ];

    public $levelColors = [
        self::LEVEL_INFO    => 'text-aqua',
        self::LEVEL_SUCCESS => 'text-green',
        self::LEVEL_ERROR   => 'text-red',
        self::LEVEL_WARNING => 'text-yellow',
    ];
    
    public function behaviors() {
        return [
            [
                'class'              => TimestampBehavior::className(),
                'createdAtAttribute' => 'created_at',
                'updatedAtAttribute' => 'updated_at',
            ],
            [
                'class'              => BlameableBehavior::className(),
                'createdByAttribute' => 'created_by',
                'updatedByAttribute' => 'updated_by',
            ],
        ];
    }
    
    public function getLevelName() {
        return \yii\helpers\Html::tag('span', $this->levelOptions[$this->level], ['class' => $this->levelColors[$this->level]]);
    }
    
    public function getTitleIcon() {
        return \yii\helpers\Html::tag('i', '', ['class' => 'fa '. $this->title_icon . ' ' .$this->levelColors[$this->level] ]);
    }
}
